1 DATA

## Longitudinal data
data_sum <- loadlongitudinaldata(dataset = "DATA_Adults_G1G29.csv", rm_generation1 = 1,rm_generation2 = 7,rm_generation3 = 29)

## Phenotyping steps
data_G0 <- loadfitnessdata(dataset = "Selection_Phenotypage_G0_G7_G8.csv", generation = "G1")
data_G7 <- loadfitnessdata(dataset = "Selection_Phenotypage_G0_G7_G8.csv", generation = "G7")
data_G29 <- loadfitnessdata(dataset = 
                            "PERFORMANCE_Comptage_adultes_G13G14G15G16G17G18G19G20G21G22G23G24G25G26G27G28G29.csv",
                            generation = "29")

2 SUP: Pairwise of Fitness difference

2.1 Data

#Compute log change
data_logchange<-computelogchange(fitness_dataset_intermediate = data_G7, fitness_dataset_final = data_G29)

#Formatting for plotting pairwise
EC_Cran_Cher_G7<-formattingplotpair(data_logchange, "7", "Cherry", "Cranberry")
EC_Straw_Cran_G7<-formattingplotpair(data_logchange, "7", "Cranberry", "Strawberry")
EC_Straw_Cher_G7<-formattingplotpair(data_logchange, "7", "Strawberry", "Cherry")
EC_Cran_Cher_G29<-formattingplotpair(data_logchange, "29", "Cherry", "Cranberry")
EC_Straw_Cran_G29<-formattingplotpair(data_logchange, "29", "Cranberry", "Strawberry")
EC_Straw_Cher_G29<-formattingplotpair(data_logchange, "29", "Strawberry", "Cherry")

2.2 Plot

#Limit axis 
lim_G7<-max(abs(min(data_logchange[data_logchange$Generation=="7",]$logchange-
                      1.96*data_logchange[data_logchange$Generation=="7",]$sd_logchange, na.rm = T)),
            max(data_logchange[data_logchange$Generation=="7",]$logchange+
                  1.96*data_logchange[data_logchange$Generation=="7",]$sd_logchange, na.rm = T))

lim_G29<-max(abs(min(data_logchange[data_logchange$Generation=="29",]$logchange-
                       1.96*data_logchange[data_logchange$Generation=="29",]$sd_logchange, na.rm = T)),
            max(data_logchange[data_logchange$Generation=="29",]$logchange+
                  1.96*data_logchange[data_logchange$Generation=="29",]$sd_logchange, na.rm = T))

#Plot
PAIR_StrawCran_G7<-ggplot(data = EC_Straw_Cran_G7,
                          aes(x = logchange_Strawberry,y = logchange_Cranberry, color=Fruit_s, group = Line)) +
  geom_errorbar(aes(ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                    ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry),
                width=0.02,size=0.2,alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                     xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
                 height=0.02,size=0.2,alpha=1) + 
  geom_point(shape=21, size=3,  fill = "#ffffff", stroke=1.3) + 
  xlab("Fitness difference\nin strawberry")  +     
  ylab("Fitness difference\nin cranberry")  +
  xlim(-lim_G7,lim_G7) + 
  ylim(-lim_G7,lim_G7) +  
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  theme(axis.title.x = element_text(size=10, colour = "#3FAA96"),
        axis.title.y = element_text(size=10, colour = "#FDB424")) +
  theme_LO_sober
 PAIR_StrawCran_G7

PAIR_StrawChe_G7<-ggplot(data = EC_Straw_Cher_G7,
                         aes(x = logchange_Cherry,y = logchange_Strawberry, group=Line, color=Fruit_s)) + 
  geom_errorbar(aes(ymin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                    ymax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
                  width=0.02, size=0.2, alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Cherry-1.96*sd_logchange_Cherry,
                     xmax = logchange_Cherry+1.96*sd_logchange_Cherry),
                  height=0.02, size=0.2, alpha=1) + 
  geom_point(shape=21, size=3,  fill = "#ffffff", stroke=1.3) + 
  ylab("Fitness difference\nin strawberry")  + 
  xlab("Fitness difference\nin cherry")  + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  xlim(-lim_G7,lim_G7) + 
  ylim(-lim_G7,lim_G7) +    
  theme(axis.title.x = element_text(size=10, colour = "#BC3C6D"),
           axis.title.y = element_text(size=10, colour = "#3FAA96")) +
  theme_LO_sober
 PAIR_StrawChe_G7

PAIR_CheCran_G7<-ggplot(data = EC_Cran_Cher_G7,aes(x = logchange_Cranberry,y = logchange_Cherry, 
                                          group=Line, color=Fruit_s)) + 
  geom_errorbar(aes(ymin = logchange_Cherry-1.96*sd_logchange_Cherry,
                      ymax = logchange_Cherry+1.96*sd_logchange_Cherry),
                  width=0.02, size=0.2, alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                       xmax = logchange_Cranberry+1.96*sd_logchange_Cranberry),
                  height=0.02, size=0.2, alpha=1) + 
  geom_point(shape=21, size=3,  fill = "#ffffff", stroke=1.3) + 
  ylab("Fitness difference\nin cherry")  + 
  xlab("Fitness difference\nin cranberry")  + 
  xlim(-lim_G7, lim_G7) + 
  ylim(-lim_G7, lim_G7) +     
  scale_color_manual(values = c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  theme_LO_sober + 
  theme(axis.title.x = element_text(colour = "#FDB424"),
        axis.title.y = element_text(colour = "#BC3C6D")) 
 PAIR_CheCran_G7

################## Final phenotyping step
#Plot
PAIR_CranStraw_G29<-ggplot(data = EC_Straw_Cran_G29,
                          aes(x = logchange_Strawberry, y = logchange_Cranberry,  color=Fruit_s,group=Line)) + 
  geom_errorbar(aes(ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                      ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry),
                  width=0.02,size=0.2,alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                       xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
                  height=0.02,size=0.2,alpha=1) + 
  geom_point(aes(fill = Fruit_s),shape=21, size=3) + 
  xlab("Fitness difference\nin strawberry")  +     
  ylab("Fitness difference\nin cranberry")  +
  xlim(-lim_G29,lim_G29) + 
  ylim(-lim_G29,lim_G29) +     
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  theme(axis.title.x = element_text(size=10, colour = "#3FAA96"),
        axis.title.y = element_text(size=10, colour = "#FDB424")) +
  theme_LO_sober
 PAIR_CranStraw_G29

PAIR_StrawChe_G29<-ggplot(data = EC_Straw_Cher_G29,
                         aes(x = logchange_Cherry,y = logchange_Strawberry, group=Line , color=Fruit_s)) + 
  geom_errorbar(aes(ymin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                      ymax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
                  width=0.02,size=0.2,alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Cherry-1.96*sd_logchange_Cherry,
                       xmax = logchange_Cherry+1.96*sd_logchange_Cherry),
                  height=0.02,size=0.2,alpha=1) + 
  geom_point(aes(fill = Fruit_s),shape=21, size=3) + 
  ylab("Fitness difference\nin strawberry")  + 
  xlab("Fitness difference\nin cherry")  + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  xlim(-lim_G29,lim_G29) + 
  ylim(-lim_G29,lim_G29) +       
  theme(axis.title.x = element_text(colour = "#BC3C6D"),
           axis.title.y = element_text(colour = "#3FAA96")) +
  theme_LO_sober
 PAIR_StrawChe_G29

PAIR_CheCran_G29<-ggplot(data = EC_Cran_Cher_G29,
                         aes(x = logchange_Cranberry,y = logchange_Cherry,group=Line, color=Fruit_s)) + 
  geom_errorbar(aes(ymin = logchange_Cherry-1.96*sd_logchange_Cherry,
                      ymax = logchange_Cherry+1.96*sd_logchange_Cherry),
                  width=0.02,size=0.2,alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                       xmax = logchange_Cranberry+1.96*sd_logchange_Cranberry),
                  height=0.02,size=0.2,alpha=1) + 
  geom_point(aes(fill = Fruit_s), shape=21, size=3) + 
  ylab("Fitness difference\nin cherry")  + 
  xlab("Fitness difference\nin cranberry")  + 
  xlim(-lim_G29,lim_G29) + 
  ylim(-lim_G29,lim_G29) +   
  scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  theme_LO_sober + 
  theme(axis.title.x = element_text(colour = "#FDB424"),
        axis.title.y = element_text(colour = "#BC3C6D")) 
 PAIR_CheCran_G29

 #Legend
TEMP_data_logchange_sum_Straw_Cher_G7<-data_logchange
TEMP_data_logchange_sum_Straw_Cher_G7$Pheno<-sample(c("Intermediate", "Final"),
                                                    length(data_logchange$logchange), 
                                                    replace=TRUE)

PAIR_plot_legend<- ggplot(data=TEMP_data_logchange_sum_Straw_Cher_G7, 
                          aes(x=Treatment, y=logchange, group=Fruit_s, colour=Fruit_s,shape=Pheno)) +
  geom_errorbar(aes(ymin=logchange-1.96*sd_logchange, ymax=logchange+1.96*sd_logchange),
                  width=0.01,size=1) +
  geom_point(size=3, stroke=1.3) + 
  scale_shape_manual(name = "Phenotyping step", 
                     labels = c("Intermediate", "Final"),values=c(21,16)) +
  scale_color_manual(name= "Selection fruit", 
                     values=c("#BC3C6D", "#FDB424", "#3FAA96"), 
                     label=c("Cherry", "Cranberry", "Strawberry")) +   
  theme_LO_sober
PAIR_legend<-lemon::g_legend(PAIR_plot_legend)

rm(TEMP_data_logchange_sum_Straw_Cher_G7)





PAIR_Fig_Sup <-  cowplot::ggdraw() +
  cowplot::draw_plot(PAIR_CheCran_G7+theme(legend.position = "none"), 
            x =0.00, y = 0.5, width = 0.22, height =0.45) +
  cowplot::draw_plot(PAIR_StrawCran_G7+theme(legend.position = "none"), 
            x = 0.26, y = 0.5, width = 0.22, height = 0.45) +
  cowplot::draw_plot(PAIR_StrawChe_G7+theme(legend.position = "none"), 
            x = 0.52, y = 0.5, width = 0.22, height = 0.45) + 
  cowplot::draw_plot(PAIR_legend, x = 0.80, y = 0.5, width = 0.1, height = 0.1) +
  cowplot::draw_plot(PAIR_CheCran_G29+theme(legend.position = "none"), 
            x =0.00, y = 0, width = 0.22, height = 0.45) +
  cowplot::draw_plot(PAIR_CranStraw_G29+theme(legend.position = "none"), 
            x = 0.26, y = 0, width = 0.22, height = 0.45) +
  cowplot::draw_plot(PAIR_StrawChe_G29+theme(legend.position = "none"), 
            x = 0.52, y = 0, width = 0.22, height = 0.45) + 
  cowplot::draw_plot_label(c("Intermediate phenotyping step", "A", "B", "C", " ",
                    "Final phenotyping step", "D", "E", "F", " "),  
                  x = c(0.26,0,0.26,0.52,0.82,0.2,0,0.26,0.52,0.82), 
                  y = c(1.01,0.97,0.97,0.97,0.97,0.5,0.47, 0.47, 0.47, 0.47), 
                  hjust = c(-0.25,-0.25,-0.25,-0.25,-0.25,-0.75,-0.75,-0.75,-0.75,-0.75), 
                  vjust = c(1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5),
                  size = 14) 
 PAIR_Fig_Sup

cowplot::save_plot(file=here::here("figures", "SUPMAT_LogChange_Pairwise.pdf"), PAIR_Fig_Sup, 
                   base_height = 15/cm(1), base_width = 30/cm(1), dpi = 610)

3 SUP: Long vs Fitness

3.1 Data

#To consider fruit maternal effect and GF maternal effect: new plot 
## Y-axis = log change = log(Fitness pheno)-log(fitness initial)
## X-axis = fitness temp / fitness initial
 ## example: for CEA during first phase 
    ## log(mean (CE1 from G2 to G5) / mean (Cherry G2))

##To check with Nico: for x-axis: denominator=mean Cherry G2 or mean CE1 G2 (???????????)


####### Phenotyping steps 
#Compute log change
data_logchange <- computelogchange(fitness_dataset_intermediate = data_G7, fitness_dataset_final = data_G29)

#Remove allopatric data
data_fitness_pheno <- data_logchange[data_logchange$SA==1,]
data_fitness_pheno <- data_fitness_pheno[, c("Line", "Fruit_s", "logchange", "sd_logchange")]


####### Longitudinal data 
#Compute log change
data_logchange_long <- computelogchange_forlongdata(longitudinal_dataset = data_sum)


####### Merge data
data_compare_longitudinal_pheno <- merge(data_logchange_long,data_fitness_pheno,by=c("Line", "Fruit_s"))
data_compare_longitudinal_pheno <- droplevels(data_compare_longitudinal_pheno)

## Does not seem to be a correlation between measures
cor.test(data_compare_longitudinal_pheno$logchange[data_compare_longitudinal_pheno$Phase=="first_prepool"], data_compare_longitudinal_pheno$logchange_long[data_compare_longitudinal_pheno$Phase=="first_prepool"])
## 
##  Pearson's product-moment correlation
## 
## data:  data_compare_longitudinal_pheno$logchange[data_compare_longitudinal_pheno$Phase == "first_prepool"] and data_compare_longitudinal_pheno$logchange_long[data_compare_longitudinal_pheno$Phase == "first_prepool"]
## t = -0.37623, df = 12, p-value = 0.7133
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.6039532  0.4482880
## sample estimates:
##        cor 
## -0.1079732
cor.test(data_compare_longitudinal_pheno$logchange[data_compare_longitudinal_pheno$Phase=="second_postpool"], data_compare_longitudinal_pheno$logchange_long[data_compare_longitudinal_pheno$Phase=="second_postpool"])
## 
##  Pearson's product-moment correlation
## 
## data:  data_compare_longitudinal_pheno$logchange[data_compare_longitudinal_pheno$Phase == "second_postpool"] and data_compare_longitudinal_pheno$logchange_long[data_compare_longitudinal_pheno$Phase == "second_postpool"]
## t = 0.91427, df = 9, p-value = 0.3844
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.3737080  0.7587141
## sample estimates:
##       cor 
## 0.2915193
####### Geary test
#Lines: CE2 and CR2 do not pass Geary's test (the threshold of a standardized mean greater than 3)
data_compare_longitudinal_pheno$Line_type  <- ifelse(data_compare_longitudinal_pheno$Line == "CR2"|
                                                       data_compare_longitudinal_pheno$Line == "CE2", "solid","dashed")

3.2 PLOT Step=f(Phase)

PLOT_IntermediatePheno_LOGCHANGE<-ggplot(data=data_compare_longitudinal_pheno[data_compare_longitudinal_pheno$Phase=="first_prepool",], 
       aes(y=logchange,x=logchange_long, color=Fruit_s,shape=Fruit_s, linetype=Line_type)) +
  geom_errorbar(aes(x = logchange_long, 
                    ymin = logchange-(1.96*sd_logchange), 
                    ymax = logchange+(1.96*sd_logchange)),
                  width=0.02,size=0.2,alpha=1) +
  geom_errorbarh(aes(y = logchange, 
                    xmin = logchange_long-1.96*sd_logchange_long,
                    xmax = logchange_long+1.96*sd_logchange_long),
                 height=0.02,size=0.2,alpha=1) +
  geom_point(size=3, fill = "#ffffff", stroke=1.3) +
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_shape_manual(values=c(21, 22, 24)) + 
  xlab("Fitness difference between average fitness\nacross generations 2 to 5 and generation 2") + 
  ylab("Fitness difference between\nintermediate and initial phenotyping steps") + 
  labs(color="Selection fruit", shape="Selection fruit") + 
  geom_abline(intercept = 0, slope = 1, color="black", linetype="dashed", size=0.8) +
  ylim(-1.9,0.9) + 
  xlim(-1.9,0.9) +
  guides(linetype=FALSE) +
  ggtitle("Intermediate phenotyping step vs. Phase 1") +
  theme_LO_sober 
PLOT_IntermediatePheno_LOGCHANGE 

PLOT_FinalPheno_LOGCHANGE <- 
  ggplot(data=data_compare_longitudinal_pheno
                        [data_compare_longitudinal_pheno$Phase=="second_postpool",], 
                        aes(y=logchange, x=logchange_long, 
                            color=Fruit_s, shape=Fruit_s, fill=Fruit_s, linetype=Line_type)) +
  geom_errorbar(aes(x = logchange_long, 
                    ymin = logchange-(1.96*sd_logchange),
                    ymax = logchange+(1.96*sd_logchange)),
                  width=0.02,size=0.2,alpha=1) +
  geom_errorbarh(aes(y = logchange, 
                    xmin = logchange_long-1.96*sd_logchange_long,
                    xmax = logchange_long+1.96*sd_logchange_long),
                 height=0.02,size=0.2,alpha=1) +
  geom_abline(intercept = 0, slope = 1, color="black", 
                 linetype="dashed", size=0.8) +
  geom_point(size=3, stroke=1) +
  scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_shape_manual(values=c(21, 22, 24)) + 
  xlab("Fitness difference between average fitness\nacross generations 13 to 26 and generation 2") + 
  ylab("Fitness difference between\nfinal and initial phenotyping steps") + 
  labs(color="Selection fruit", shape="Selection fruit", fill="Selection fruit") + 
  ylim(-0.5,1.7) +
  xlim(-0.5,1.7) +
  guides(linetype=FALSE) +
  ggtitle("Final phenotyping step vs. Phase 3") +
  theme_LO_sober
PLOT_FinalPheno_LOGCHANGE  

PLOT_Comparison_Pheno_Longitudinal_LOGCHANGE <- cowplot::ggdraw() +
  cowplot::draw_plot(PLOT_IntermediatePheno_LOGCHANGE + 
                       theme(axis.title.y = element_text(size=10),
                             axis.title.x = element_text(size=10)),
            x = 0, y = 0.5, width = 1, height = 0.5) +
  cowplot::draw_plot(PLOT_FinalPheno_LOGCHANGE + 
                       theme(axis.title.y = element_text(size=10),
                             axis.title.x = element_text(size=10)),
            x =0, y = 0, width = 1, height = 0.5) +
  cowplot::draw_plot_label(c("A", "B"),  
                  x = c(0,0), y = c(1,0.5), 
                  size = 14) 
PLOT_Comparison_Pheno_Longitudinal_LOGCHANGE

cowplot::save_plot(file=here::here("figures", "SUPMAT_LogChange_Pheno_Longitudinal.pdf"),
                   PLOT_Comparison_Pheno_Longitudinal_LOGCHANGE, base_height = 20/cm(1), base_width = 15/cm(1), dpi = 1200)

3.3 PLOT Step/Phase=f(Phase)

PLOT_IntermediatePheno_TEMP<-ggplot(data=data_compare_longitudinal_pheno[data_compare_longitudinal_pheno$Phase=="first_prepool",], 
       aes(y=logchange/logchange_long,x=logchange_long, color=Fruit_s,shape=Fruit_s)) +
  geom_errorbarh(aes(y = logchange/logchange_long, 
                    xmin = logchange_long-1.96*sd_logchange_long,
                    xmax = logchange_long+1.96*sd_logchange_long, 
                    linetype=Line_type),
                 height=0.02,size=0.2,alpha=1) +
  geom_point(size=3, fill = "#ffffff", stroke=1.3) +
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_shape_manual(values=c(21, 22, 24)) + 
  xlab("Fitness difference between average fitness\nacross generations 2 to 5 and generation 2") + 
  ylab("Fitness difference between phenotyping steps /\nFitness difference between phases") + 
  labs(color="Selection fruit", shape="Selection fruit") + 
  geom_abline(intercept = 0, slope = 1, color="black", linetype="dashed", size=0.8) +
  ylim(-3.9,4.4) +
  xlim(-3.9,4.4) +
  ggtitle("Intermediate phenotyping step vs. Phase 1") +
  theme_LO_sober 
PLOT_IntermediatePheno_TEMP 

PLOT_FinalPheno_TEMP <- ggplot(data=data_compare_longitudinal_pheno
                        [data_compare_longitudinal_pheno$Phase=="second_postpool",], 
                        aes(y=logchange/logchange_long,x=logchange_long, color=Fruit_s,shape=Fruit_s,fill=Fruit_s)) +
  geom_errorbarh(aes(y = logchange/logchange_long, 
                    xmin = logchange_long-1.96*sd_logchange_long,
                    xmax = logchange_long+1.96*sd_logchange_long, 
                    linetype=Line_type),
                 height=0.02,size=0.2,alpha=1) +
  geom_abline(intercept = 0, slope = 1, color="black", 
                 linetype="dashed", size=0.8) +
  geom_point(size=3, stroke=1) +
  scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_shape_manual(values=c(21, 22, 24)) + 
  xlab("Fitness difference between average fitness\nacross generations 13 to 26 and generation 2") + 
  ylab("Fitness difference between phenotyping steps /\nFitness difference between phases") + 
  labs(color="Selection fruit", shape="Selection fruit", fill="Selection fruit") + 
  ylim(-0.5,1.7) +
  xlim(-0.5,1.7) +
  ggtitle("Final phenotyping step vs. Phase 3") +
  theme_LO_sober
PLOT_FinalPheno_TEMP  

PLOT_Comparison_TEMP <- cowplot::ggdraw() +
  cowplot::draw_plot(PLOT_IntermediatePheno_TEMP + 
                       theme(axis.title.y = element_text(size=10),
                             axis.title.x = element_text(size=10)),
            x = 0, y = 0.5, width = 1, height = 0.5) +
  cowplot::draw_plot(PLOT_FinalPheno_TEMP + 
                       theme(axis.title.y = element_text(size=10),
                             axis.title.x = element_text(size=10)),
            x =0, y = 0, width = 1, height = 0.5) +
  cowplot::draw_plot_label(c("A", "B"),  
                  x = c(0,0), y = c(1,0.5), 
                  size = 14) 
PLOT_Comparison_TEMP

cowplot::save_plot(file=here::here("figures", "SUPMAT_LogChange_Pheno-div-Long_Longitudinal.pdf"),
                   PLOT_Comparison_TEMP, base_height = 20/cm(1), base_width = 15/cm(1), dpi = 1200)

3.4 PLOT Maternal effects

m <- lm(logchange ~ logchange_long + offset(logchange_long),
        data = data_compare_longitudinal_pheno[data_compare_longitudinal_pheno$Phase=="second_postpool",]) 

# le summary permet directement de vérifier si la pente est significativement différente de 1 à partir de la p-value associée à la variable logchange_long et de tester si l'évolution du changement maternel est significatif (p-value associée à l'intercept)

summary(m)
## 
## Call:
## lm(formula = logchange ~ logchange_long + offset(logchange_long), 
##     data = data_compare_longitudinal_pheno[data_compare_longitudinal_pheno$Phase == 
##         "second_postpool", ])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.31398 -0.17353 -0.05823  0.12347  0.53029 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)   
## (Intercept)     0.05477    0.21373   0.256  0.80351   
## logchange_long -0.81441    0.20300  -4.012  0.00306 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2743 on 9 degrees of freedom
## Multiple R-squared:  0.08498,    Adjusted R-squared:  -0.01669 
## F-statistic: 0.8359 on 1 and 9 DF,  p-value: 0.3844
#pval of logchange_long = 0.003 => slope is different of 1 
#pval of Intercept = 0.80 => no evolution of maternal effect??? 


## Ratio effet maternels pop dérivée sur effet maternels pop ancestrale??
exp(coef(m)[1]) 
## (Intercept) 
##    1.056301
# proportion of adaptation due to maternal effects
data_compare_longitudinal_pheno$mateff <- (data_compare_longitudinal_pheno$logchange_long -
  data_compare_longitudinal_pheno$logchange) / data_compare_longitudinal_pheno$logchange_long

data_compare_longitudinal_pheno
##    Line    Fruit_s           Phase logchange_long sd_logchange_long   logchange
## 1   CE1     Cherry   first_prepool     0.33816796        0.04332430 -0.27403677
## 2   CE2     Cherry   first_prepool     0.14436267        0.05963021 -0.56171884
## 3   CE3     Cherry   first_prepool     0.46747518        0.05873193  0.18528246
## 4   CE4     Cherry   first_prepool     0.39817852        0.03355308  0.12791340
## 5   CEA     Cherry second_postpool     1.57245790        0.02955303  0.14767000
## 6   CEB     Cherry second_postpool     1.55711969        0.02872255  0.25038029
## 7   CEC     Cherry second_postpool     1.61441010        0.02863731  0.35854062
## 8   CR1  Cranberry   first_prepool    -0.41891064        0.06108829  0.26983737
## 9   CR2  Cranberry   first_prepool    -0.44425078        0.02665804 -0.10684877
## 10  CR3  Cranberry   first_prepool    -0.08878235        0.03934015  0.05809882
## 11  CR4  Cranberry   first_prepool    -0.31794722        0.05591827  0.35156311
## 12  CR5  Cranberry   first_prepool    -0.44134580        0.07287785  0.18840336
## 13  CRA  Cranberry second_postpool     0.49072243        0.02497960 -0.14885350
## 14  CRB  Cranberry second_postpool     0.60455161        0.02677848  0.29719689
## 15  CRC  Cranberry second_postpool     0.64866188        0.02340626  0.02703717
## 16  CRD  Cranberry second_postpool     0.55460135        0.02652983 -0.15627744
## 17  CRE  Cranberry second_postpool     0.75471935        0.02312381  0.72513486
## 18  FR1 Strawberry   first_prepool     0.39149042        0.03843131  0.33051044
## 19  FR2 Strawberry   first_prepool    -0.24506580        0.06386743  0.09022737
## 20  FR3 Strawberry   first_prepool     0.08495270        0.03464317  0.13335674
## 21  FR4 Strawberry   first_prepool     0.13293173        0.03338454  0.58063316
## 22  FR5 Strawberry   first_prepool    -0.41701639        0.03195222  0.18650420
## 23  FRA Strawberry second_postpool     0.86504109        0.03421319  0.15709032
## 24  FRB Strawberry second_postpool     0.96698510        0.03291146  0.56023100
## 25  FRC Strawberry second_postpool     1.05024613        0.03374030  0.36640738
##    sd_logchange Line_type      mateff
## 1    0.25731181    dashed  1.81035697
## 2    0.57349396     solid  4.89102546
## 3    0.11827433    dashed  0.60365285
## 4    0.24311831    dashed  0.67875364
## 5    0.15742840    dashed  0.90608970
## 6    0.10098643    dashed  0.83920293
## 7    0.11692997    dashed  0.77791231
## 8    0.21318308    dashed  1.64414066
## 9    0.46435229     solid  0.75948546
## 10   0.13676999    dashed  1.65439607
## 11   0.12714934    dashed  2.10572789
## 12   0.14497197    dashed  1.42688378
## 13   0.11935520    dashed  1.30333542
## 14   0.15311973    dashed  0.50840113
## 15   0.11563812    dashed  0.95831855
## 16   0.11566948    dashed  1.28178337
## 17   0.12754300    dashed  0.03919933
## 18   0.08222221    dashed  0.15576367
## 19   0.17892718    dashed  1.36817612
## 20   0.16884574    dashed -0.56977628
## 21   0.13295026    dashed -3.36790492
## 22   0.25058617    dashed  1.44723471
## 23   0.14115599    dashed  0.81840132
## 24   0.12842826    dashed  0.42064154
## 25   0.12011698    dashed  0.65112237
#Plot
PLOT_Maternaleffects<-ggplot(data=data_compare_longitudinal_pheno, 
       aes(y=mateff,x=logchange_long, color=Fruit_s, shape=Fruit_s, fill=interaction(Phase,Fruit_s))) +
  geom_point(size=3,  stroke=1.3) +
  scale_fill_manual(name = "Phase", 
                      values = c("#ffffff","#BC3C6D", "#ffffff","#FDB424", "#ffffff", "#3FAA96"), 
                      breaks = c("first_prepool.Cherry", "second_postpool.Cherry"), 
                      labels = c("Phase 1","Phase 3")) +
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_shape_manual(values=c(21, 22, 24)) + 
  xlab("Fitness difference between average fitness\nacross generations 2 to 5 (13 to 26) and generation 2") + 
  ylab("Proportion of adaptation\ndue to evolution of maternal effects") + 
  labs(color="Selection fruit", shape="Selection fruit") + 
  guides(fill = guide_legend(override.aes = list(fill = c("white","black"), shape=21))) +
  theme_LO_sober 
PLOT_Maternaleffects 

cowplot::save_plot(file=here::here("figures", "SUPMAT_Maternal_effects.pdf"),
                   PLOT_Maternaleffects, base_height = 20/cm(1), base_width = 15/cm(1), dpi = 1200)

4 SUP: Adaptation 8fruits

4.1 Longitudinal data

data_sum_allfruits <- loadlongitudinaldata_allfruits(dataset = "DATA_Adults_G1G29.csv", rm_generation_max = 5)
data_sum_allfruits_AN<-data_sum_allfruits[data_sum_allfruits$Generation!=1,]

4.2 Analysis

#Models
mod_all_interaction <- lme4::lmer(fitness ~ Fruit_s*Generation + (1|Generation) + (1|Generation:Fruit_s), 
            weights = N, data = data_sum_allfruits_AN)

mod_all_fruit_generation<- lme4::lmer(fitness ~ Fruit_s+Generation + (1|Generation) + (1|Generation:Fruit_s) , 
            weights = N, data = data_sum_allfruits_AN)

mod_all_fruit<- lme4::lmer(fitness ~ Fruit_s + (1|Generation) + (1|Generation:Fruit_s) , 
            weights = N, data = data_sum_allfruits_AN)

mod_all_null<- lme4::lmer(fitness ~ 1  + (1|Generation) + (1|Generation:Fruit_s), 
            weights = N, data = data_sum_allfruits_AN)

MuMIn::model.sel(mod_all_interaction,mod_all_fruit_generation,mod_all_fruit,mod_all_null)
## Model selection table 
##                            (Int) Frt_s      Gnr Frt_s:Gnr             family df
## mod_all_fruit            -2.4510     +                    gaussian(identity) 11
## mod_all_fruit_generation -2.4100     + -0.02122           gaussian(identity) 12
## mod_all_interaction      -1.2580     + -0.56070         + gaussian(identity) 19
## mod_all_null             -0.9595                          gaussian(identity)  4
##                            logLik  AICc delta weight
## mod_all_fruit             -98.116 221.0  0.00  0.942
## mod_all_fruit_generation  -99.726 226.8  5.76  0.053
## mod_all_interaction       -92.293 231.3 10.31  0.005
## mod_all_null             -115.017 238.4 17.42  0.000
## Models ranked by AICc(x) 
## Random terms (all models): 
## '1 | Generation', '1 | Generation:Fruit_s'
#Posthoc
emmeans::emmeans(mod_all_fruit, list(pairwise ~ Fruit_s), adjust = "tukey") #
## $`emmeans of Fruit_s`
##  Fruit_s      emmean    SE  df lower.CL upper.CL
##  Blackcurrant -2.451 0.286 356   -3.237  -1.6654
##  Cherry       -0.528 0.168 423   -0.987  -0.0679
##  Cranberry    -0.483 0.155 487   -0.907  -0.0595
##  Fig          -0.963 0.196 347   -1.501  -0.4253
##  Grape        -2.437 0.357 272   -3.419  -1.4553
##  Rosehips     -2.076 0.285 367   -2.859  -1.2934
##  Strawberry   -0.424 0.160 426   -0.864   0.0148
##  Tomato       -1.505 0.338 149   -2.441  -0.5692
## 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95 
## Conf-level adjustment: sidak method for 8 estimates 
## 
## $`pairwise differences of Fruit_s`
##  contrast                  estimate    SE  df t.ratio p.value
##  Blackcurrant - Cherry      -1.9237 0.328 348 -5.857  <.0001 
##  Blackcurrant - Cranberry   -1.9681 0.323 361 -6.102  <.0001 
##  Blackcurrant - Fig         -1.4882 0.342 321 -4.346  0.0005 
##  Blackcurrant - Grape       -0.0141 0.448 261 -0.032  1.0000 
##  Blackcurrant - Rosehips    -0.3750 0.397 313 -0.945  0.9813 
##  Blackcurrant - Strawberry  -2.0267 0.325 350 -6.235  <.0001 
##  Blackcurrant - Tomato      -0.9460 0.433 181 -2.185  0.3658 
##  Cherry - Cranberry         -0.0444 0.226 381 -0.196  1.0000 
##  Cherry - Fig                0.4355 0.255 329  1.709  0.6813 
##  Cherry - Grape              1.9096 0.391 282  4.884  <.0001 
##  Cherry - Rosehips           1.5487 0.327 349  4.733  0.0001 
##  Cherry - Strawberry        -0.1030 0.229 358 -0.449  0.9998 
##  Cherry - Tomato             0.9777 0.373 167  2.624  0.1547 
##  Cranberry - Fig             0.4799 0.247 349  1.943  0.5222 
##  Cranberry - Grape           1.9539 0.386 287  5.060  <.0001 
##  Cranberry - Rosehips        1.5931 0.321 364  4.957  <.0001 
##  Cranberry - Strawberry     -0.0587 0.221 383 -0.266  1.0000 
##  Cranberry - Tomato          1.0220 0.368 169  2.780  0.1072 
##  Fig - Grape                 1.4741 0.403 271  3.662  0.0072 
##  Fig - Rosehips              1.1132 0.341 319  3.263  0.0265 
##  Fig - Strawberry           -0.5386 0.250 332 -2.152  0.3841 
##  Fig - Tomato                0.5421 0.384 164  1.411  0.8509 
##  Grape - Rosehips           -0.3609 0.448 267 -0.806  0.9927 
##  Grape - Strawberry         -2.0126 0.388 283 -5.184  <.0001 
##  Grape - Tomato             -0.9319 0.480 175 -1.943  0.5235 
##  Rosehips - Strawberry      -1.6518 0.324 353 -5.101  <.0001 
##  Rosehips - Tomato          -0.5711 0.432 180 -1.322  0.8896 
##  Strawberry - Tomato         1.0807 0.370 167  2.923  0.0745 
## 
## Degrees-of-freedom method: kenward-roger 
## P value adjustment: tukey method for comparing a family of 8 estimates
mod_all_fruit<- lme4::lmer(fitness ~ Fruit_s -1+ (1|Generation) + (1|Generation:Fruit_s) , 
            weights = N, data = data_sum_allfruits)
summary(mod_all_fruit)
## Linear mixed model fit by REML ['lmerMod']
## Formula: fitness ~ Fruit_s - 1 + (1 | Generation) + (1 | Generation:Fruit_s)
##    Data: data_sum_allfruits
## Weights: N
## 
## REML criterion at convergence: 258.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7627 -0.6555  0.1107  0.5521  2.8168 
## 
## Random effects:
##  Groups             Name        Variance Std.Dev.
##  Generation:Fruit_s (Intercept) 0.1504   0.3879  
##  Generation         (Intercept) 0.1323   0.3637  
##  Residual                       2.1944   1.4813  
## Number of obs: 147, groups:  Generation:Fruit_s, 33; Generation, 5
## 
## Fixed effects:
##                     Estimate Std. Error t value
## Fruit_sBlackcurrant  -1.7039     0.3351  -5.084
## Fruit_sCherry        -0.3605     0.2572  -1.402
## Fruit_sCranberry     -0.3561     0.2522  -1.412
## Fruit_sFig           -0.8134     0.2799  -2.906
## Fruit_sGrape         -1.9430     0.3575  -5.435
## Fruit_sRosehips      -1.5403     0.3276  -4.701
## Fruit_sStrawberry    -0.2591     0.2540  -1.020
## Fruit_sTomato        -1.9056     0.3355  -5.680
## 
## Correlation of Fixed Effects:
##             Frt_sB Frt_sCh Frt_sCr Frt_sF Frt_sG Frt_sR Frt_sS
## Frut_sChrry 0.318                                             
## Frt_sCrnbrr 0.320  0.409                                      
## Fruit_sFig  0.316  0.375   0.382                              
## Fruit_sGrap 0.285  0.299   0.300   0.297                      
## Frut_sRshps 0.298  0.324   0.327   0.322  0.285               
## Frt_sStrwbr 0.319  0.407   0.414   0.378  0.299  0.325        
## Fruit_sTomt 0.288  0.316   0.319   0.314  0.275  0.290  0.318

4.3 Plot

pd <- position_dodge(0.3) # move them .05 to the left and right


PLOT_ALLFRUITS<-ggplot(data=data_sum_allfruits, 
                            aes(x=factor(Generation),group=Line, y=fitness, colour=Fruit_s)) + 
  facet_wrap(~ Fruit_s, nrow = 8) +
  geom_errorbar(aes(ymin=fitness-1.96*se_fitness, ymax=fitness+1.96*se_fitness),
                width=.1,position=pd,size=0.2,color="black") +
  geom_line(size=0.3,position=pd) +
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylab("Fitness") + 
  xlab("Generation") + 
  theme_LO_sober
PLOT_ALLFRUITS

#Extract slope and intercept
dat_8fruits <- expand.grid(Generation=as.numeric(levels(as.factor(data_sum_allfruits_AN$Generation))),
                           Fruit_s=unique(data_sum_allfruits_AN$Fruit_s))
dat_8fruits$fitness_predicted <- predict(mod_all_fruit, newdata = dat_8fruits, 
                          re.form= NA, type = "response")





PLOT_CHERRY <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Cherry",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  # geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Cherry",], 
  #                    aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) + 
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  ylab("Fitness") + 
  xlab("Generation") + 
  xlim("1","2","3","4","5") +
  scale_color_manual(values = c("#BC3C6D")) + 
  ggtitle("Cherry") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#BC3C6D"))
PLOT_CHERRY

PLOT_CRANBERRY <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Cranberry",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  # geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Cranberry",], 
  #                    aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) + 
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  ylab("Fitness") + 
  xlim("1","2","3","4","5") +
  xlab("Generation") + 
  scale_color_manual(values = c("#FDB424")) + 
  ggtitle("Cranberry") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#FDB424"))
PLOT_CRANBERRY

PLOT_STRAWBERRY <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Strawberry",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  # geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Strawberry",], 
  #                    aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) + 
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c("#3FAA96")) + 
  ggtitle("Strawberry") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#3FAA96"))
PLOT_STRAWBERRY

PLOT_GRAPE <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Grape",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  # geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Grape",], 
  #                    aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) + 
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c("#7B7554")) + 
  ggtitle("Grape") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#7B7554"))
PLOT_GRAPE

PLOT_ROSEHIPS <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Rosehips",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  # geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Rosehips",], 
  #                    aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) + 
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c("#8ACDEA")) + 
  ggtitle("Rose hips") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#8ACDEA"))
PLOT_ROSEHIPS

PLOT_TOMATO <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Tomato",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  # geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Tomato",], 
  #                    aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) + 
  geom_point(size = 2, position = pd, shape = 21, fill = "white", stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c( "#ED6F47")) + 
  ggtitle("Tomato") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#ED6F47"))
PLOT_TOMATO

PLOT_FIG <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Fig",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  # geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Fig",], 
  #                    aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) + 
  geom_point(size = 2, position = pd, shape = 21, fill = "white", stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c("#93194F")) + 
  ggtitle("Fig") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#93194F"))
PLOT_FIG

PLOT_BLACKCURRANT <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Blackcurrant",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  # geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Blackcurrant",], 
  #                    aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) + 
  geom_point(size = 2, position = pd, shape = 21, fill = "white", stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c( "#203753")) + 
  ggtitle("Blackcurrant") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#203753"))
PLOT_BLACKCURRANT

DYNAMIC_EIGHT_JOIN <- cowplot::ggdraw() + 
  cowplot::draw_plot(PLOT_STRAWBERRY, x = 0, y = 0, width = 0.5, height = 0.28) + 
  cowplot::draw_plot(PLOT_GRAPE+ theme(axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0, y = 0.28, width = 0.5, height = 0.23) + 
  cowplot::draw_plot(PLOT_CRANBERRY+ theme(axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0, y = 0.53, width = 0.5, height = 0.23) + 
  cowplot::draw_plot(PLOT_BLACKCURRANT+ theme(axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0, y = 0.77, width = 0.5, height = 0.23) + 
  cowplot::draw_plot(PLOT_TOMATO+ theme(axis.title.y = element_blank()), 
                     x = 0.5, y = 0, width = 0.5, height = 0.28) + 
  cowplot::draw_plot(PLOT_ROSEHIPS+ theme(axis.title.y = element_blank(),
                                              axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0.5, y = 0.28, width = 0.5, height = 0.23) + 
  cowplot::draw_plot(PLOT_FIG+ theme(axis.title.y = element_blank(),
                                              axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0.5, y = 0.53, width = 0.5, height = 0.23) + 
  cowplot::draw_plot(PLOT_CHERRY + theme(axis.title.y = element_blank(),
                                              axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0.5, y = 0.77, width = 0.5, height = 0.23) +
  cowplot::draw_plot_label(c("A", "C",  "E", "G", "B",  "D", "F",  "H"),  
                  x = c(0, 0, 0, 0, 0.5, 0.5, 0.5, 0.5), 
                  y = c(1, 0.75, 0.50, 0.27, 1, 0.75, 0.5, 0.27), 
                  hjust = c(-0.5, -0.5, -0.5,-0.5, -0.5, -0.5, -0.5, -0.5), 
                  vjust = c(1.5, 1.5, 1.5,1.5, 1.5, 1.5,1.5, 1.5),
                  size = 12) 
 DYNAMIC_EIGHT_JOIN

cowplot::save_plot(file =here::here("figures", "SUPMAT_Fitness8Fruits.pdf"), DYNAMIC_EIGHT_JOIN, base_height = 17/cm(1), base_width = 15/cm(1), dpi = 1200)